package cn.ycc1.user.controller;

import cn.ycc1.user.entity.User;
import cn.ycc1.user.service.UserService;
import cn.ycc1.user.vo.UserDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Title:
 * @Author ycc
 * @Date 2023/7/8 19:50
 */
@RestController
@RequestMapping("user")
@Api(tags = "库存管理")
public class UserController {
    @Autowired
    UserService userService;

    @GetMapping("/findByUsername/{username}")
    @ApiOperation(value = "获取用户信息")
    public User findByUsername(@PathVariable("username") String username) {
        return userService.findByUsername(username);
    }

    @GetMapping("/findByUserId/{userId}")
    @ApiOperation(value = "获取用户信息")
    public User findByUserId(@PathVariable("userId") Long userId) throws InterruptedException {
        if(userId == 1) {
            Thread.sleep(60);
        } else if(userId == 2) {
            throw new RuntimeException("故意报错，触发熔断");
        }
        return userService.findByUserId(userId);
    }
}
